package leetcodecompetition.D372;

/**
 * @Author: Siantar
 * @Date: 2023-11-19-10:57
 * @Description: 1.0
 */
public class T100119 {
    public int maximumXorProduct(long a, long b, int n) {
        if (a < b) {
            a = a ^ b;
            b = a ^ b;
            a = a ^ b;
        }
        long mask = (1L << n) - 1;
        long ax = a & ~mask;
        long bx = b & ~mask;
        a = a & mask;
        b = b & mask;

        long left = a ^ b;
        long one = mask ^ left;
        ax |= one;
        bx |= one;
        if (ax == bx && left != 0) {
            long highBit = 1L << (63 - Long.numberOfLeadingZeros(left));
            ax |= highBit;
            left ^= highBit;
        }
        bx |= left;
        long MOD = 1_000_000_007;
        return (int) (ax % MOD * (bx % MOD) % MOD);
    }
}
